﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Portal
{
    public interface IRepository<T>
    {

        T CreateEntity();

        /// <summary>
        /// 获取表IQueryable 
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Get();

        long Count();

        /// <summary>
        /// 根据条件获取表IQueryable 
        /// </summary>
        /// <returns></returns>
        IQueryable<T> Get(Expression<Func<T, bool>> expression);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sort"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        IQueryable<T> GetSort(string sort = "Id", string order = "DESC");
        /// <summary>
        /// 根据条件获取表IQueryable 
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetSort(Expression<Func<T, bool>> expression, string sort = "Id", string order = "DESC");
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="t"></param>
        void Add(T t);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="t"></param>
        void Update(T t);

        void AddOrUpdate(T t);

        /// <summary>
        /// 删除一个实体
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        void Delete(T t);
        /// <summary>
        /// 根据条件删除实体
        /// </summary>
        /// <param name="expression"></param>
        void Delete(Expression<Func<T, bool>> expression);
        /// <summary>
        /// 保存
        /// </summary>
        void Save();


    }
}
